package com.tang.exception_.try_;

public class TryCatchExercise01 {
    //编写一个main方法
    public static void main(String[] args) {
        Exception01.main(args);
    }
}

class Exception01{
    public static int method() {
        try {
            String[] names = new String[3];//String[]数组
//            names[1]="tom";
            names=null;
            if (names[1].equals("tom")) {//NullPointerException
                System.out.println(names[1]);
            } else {
                names[3] = "ttt";
            }
            return 1;
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("ArrayIndexOutOfBoundsException");
            return 2;
        } catch (NullPointerException e) {//捕获
            System.out.println("NullPointerException");
            return 3; // finally 必须执行所以
        } finally { //必须执行
            return 4; //返回4
        }
    }
    public static void main(String[] args) {
        System.out.println(method()); //4
    }
}
